/**
* 医院相关数据表设计
**/
var mongoose = require('mongoose');

var HospitalSchema = new mongoose.Schema({
  hcode:String,//医院编码
  name:{
    type: String,
    unique: true,
    required: true
  },
  address:String,
  gpsinfo:String,
  introduction:String,
  doclist:[String],
  status:{type:String,default:'1',enum: ['1', '0']},
  createdOn: {
    type: Date,
    default: Date.now
  },
  updatedOn: {
    type: Date,
    default: Date.now
  }
});


/**
 * 初期可以将医生、护士保存在同一张表里，用一个字段来区分
 **/
var DoctorSchema = new mongoose.Schema({
  name:String,
  hid:String,//是否需要支持一个医生隶属于多家医院？
  worktel:String,
  dtype:String,//医生类型：doctor、nurse
  introduction:String,
  homeaddress:String,
  homegps:String,
  servicetime:String,//服务时间，支持变化，依次记录该医生可提供服务的时间
  servicerange:String//服务业务范围
});

/**
 * 患者表：存储患者段账信息
 **/
var PatientSchema = new mongoose.Schema({
  name:String,
  tel:String,
  comefrom:String,
  introduction:String,
  homeaddress:String,
  homegps:String
});

/**
 * 服务请求表：存储由患者发起、医护加入的服务信息
 **/

var ServiceThreadSchema = new mongoose.Schema({
  stname:String,
  did:String,
  pid:String,
  preqtime:{
    type: Date,
    default: Date.now
  },//患者下单时间
  drestime:{
    type: Date
  },//医护接单时间（抢单或系统委派后医护人员的响应时间）
  darrivedtime:Date,//医护人员到达时间
  dsendtime:Date,//医护服务结束时间
  reqtime:[],//from,to
  status:String,
  fee:Number
});


mongoose.model('Hospital', HospitalSchema);
mongoose.model('Doctor', DoctorSchema);
mongoose.model('Patient', PatientSchema);
